package co.fitstart.entity.user.investigation;

import java.beans.Transient;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.DynamicUpdate;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import co.fitstart.entity.user.User;
import co.fitstart.entity.utils.CollectionUtils;

/**
 * 
 * @author mohanlan
 *
 */
@Entity
@Table(name = "health_investigation")
@DynamicUpdate
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class HealthInvestigation {
    
    @Id
    @GeneratedValue
    private Long id;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JSONField(serialize = false)
    private User user;
    
    /** 创建时间 */
    private Date createTime;
    
    /** 疾病枚举多选值 a,b,c */
    private String disease;
    
    /** 疾病备注 */
    private String diseaseRemarks;
    
    /** 运动疾病史 */
    private String sportInjuries;
    
    /** 运动习惯 */
    private String exerciseHabit;
    
    /** 是否怀孕 */
    private String pregnant;
    
    /** 生理期 */
    private String menstruation;
    
    /** 备孕 */
    private String preparePregnant;
    
    /** 肠胃 */
    private String stomach;
    
    /** 暴食 */
    private String gluttony;
    
    /** 饮食偏好 */
    private String foodPreference;
    
    /** 工作安排 */
    private String workArrangements;
    
    /** 其他健康问题 */
    private String remarks;

    /**
     * The default constructor
     */
    public HealthInvestigation() {
    }

    /**
     * 
     * @return
     */
    public HealthInvestigation initialize() {
        this.createTime = new Date();
        return this;
    }

    /**
     * 
     * @param healthInvestigation
     * @return
     */
    public HealthInvestigation edit(HealthInvestigation healthInvestigation) {
        
        this.disease = healthInvestigation.getDisease();
        this.diseaseRemarks = healthInvestigation.getDiseaseRemarks();
        this.sportInjuries = healthInvestigation.getSportInjuries();
        this.exerciseHabit = healthInvestigation.getExerciseHabit();
        this.pregnant = healthInvestigation.getPregnant();
        this.menstruation = healthInvestigation.getMenstruation();
        this.preparePregnant = healthInvestigation.getPreparePregnant();
        this.stomach = healthInvestigation.getStomach();
        this.gluttony = healthInvestigation.getGluttony();
        this.foodPreference = healthInvestigation.getFoodPreference();
        
        return this;
    }

    /**
     * 
     * @param user
     * @return
     */
    public HealthInvestigation bindUser(User user) {
        this.user = user;
        return this;
    }

    /**
     * 
     * @return
     */
    public String genarateDisease() {
        String[] diseases = StringUtils.split(this.disease, ",");
        
        if(CollectionUtils.isArrayEmpty(diseases)) {
            return "";
        }
        
        String result = "";
        
        for(String disease : diseases) {
            Disease diseaseEnum = Disease.valueOf(disease);
            result = result + diseaseEnum.getDescription() + " <br /> ";
        }
        
        return result;
    }
    
    /**
     * Split health diseases
     * 
     * @return
     */
    @Transient
    public List<String> getDiseases() {
        
        List<String> result = new ArrayList<String>();
        String[] diseases = StringUtils.split(this.disease, ",");
        
        if(!CollectionUtils.isArrayEmpty(diseases)) {
            for(String disease : diseases) {
                result.add(disease);
            }
        }
        
        return result;
    }

    public Long getId() {
        return id;
    }

    public User getUser() {
        return user;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public String getDisease() {
        return disease;
    }

    public String getDiseaseRemarks() {
        return diseaseRemarks;
    }

    public String getSportInjuries() {
        return sportInjuries;
    }

    public String getExerciseHabit() {
        return exerciseHabit;
    }

    public String getPregnant() {
        return pregnant;
    }

    public String getMenstruation() {
        return menstruation;
    }

    public String getPreparePregnant() {
        return preparePregnant;
    }

    public String getStomach() {
        return stomach;
    }

    public String getGluttony() {
        return gluttony;
    }

    public String getFoodPreference() {
        return foodPreference;
    }

    public String getWorkArrangements() {
        return workArrangements;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public void setDisease(String disease) {
        this.disease = disease;
    }

    public void setDiseaseRemarks(String diseaseRemarks) {
        this.diseaseRemarks = diseaseRemarks;
    }

    public void setSportInjuries(String sportInjuries) {
        this.sportInjuries = sportInjuries;
    }

    public void setExerciseHabit(String exerciseHabit) {
        this.exerciseHabit = exerciseHabit;
    }

    public void setPregnant(String pregnant) {
        this.pregnant = pregnant;
    }

    public void setMenstruation(String menstruation) {
        this.menstruation = menstruation;
    }

    public void setPreparePregnant(String preparePregnant) {
        this.preparePregnant = preparePregnant;
    }

    public void setStomach(String stomach) {
        this.stomach = stomach;
    }

    public void setGluttony(String gluttony) {
        this.gluttony = gluttony;
    }

    public void setFoodPreference(String foodPreference) {
        this.foodPreference = foodPreference;
    }

    public void setWorkArrangements(String workArrangements) {
        this.workArrangements = workArrangements;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }
}
